from django.contrib.auth.models import User
from django.db import models


# Create your models here.

class UserInfo(models.Model):
    id = models.IntegerField(primary_key=True)
    username = models.CharField(max_length=60, unique=True)
    realName = models.CharField(db_column="real_name", max_length=60)
    email = models.EmailField(unique=True)
    age = models.IntegerField()
    mobile = models.CharField(max_length=11, unique=True)
    status = models.IntegerField()
    address = models.CharField(max_length=300)
    gender = models.IntegerField()
    birthday = models.DateField()
    create_time = models.DateTimeField(db_column="create_time", auto_now_add=True)
    update_time = models.DateTimeField(db_column="update_time", auto_now=True)
    creator = models.CharField(max_length=60)
    updater = models.CharField(max_length=60)
    introduction = models.TextField()

    class Meta:
        db_table = 't_user_info'

    def __init__(self, *args, **kwargs):
        super().__init__(*args, **kwargs)

    def __to_dic__(self):
        return {
            'id': self.id,
            'username': self.username,
            'realName': self.realName,
            'email': self.email,
            'mobile': self.mobile,
            'status': self.status,
            'address': self.address,
            'gender': self.gender,
            'birthday': self.birthday,
            'create_time': self.create_time.now().strftime('%Y-%m-%d %H:%M:%S'),
            'update_time': self.update_time.now().strftime('%Y-%m-%d %H:%M:%S'),
            'creator': self.creator,
            'updater': self.updater,
            'introduction': self.introduction
        }
